package org.fao.pims.web.pollneeds;

import javax.servlet.http.*;
import java.util.*;
import org.ajaxtags.servlets.BaseAjaxServlet;
import org.ajaxtags.xml.AjaxXmlBuilder;
import org.fao.pims.persistence.MyBasicDataSource;
import org.fao.pims.persistence.TaxonDAO;
import org.fao.pims.persistence.TaxonDAOImpl;

public class AutocompleteServlet extends BaseAjaxServlet {
	
	public String getXmlContent(HttpServletRequest request, HttpServletResponse response)
		throws Exception {

		String taxonNameSubString = request.getParameter("nameofcrop");
		
		System.out.println("substring: " + taxonNameSubString);
		
		TaxonDAO dao = new TaxonDAOImpl();
		
		List nameList = dao.getTaxonByName(taxonNameSubString);
		
		
		
		String xml = new AjaxXmlBuilder().addItems(nameList, "commonAndScientName", "scientificName", true).toString(); 
		
		System.out.println(xml);
		
		return xml;
	}

}
